package com.shop.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.entity.PlatformAccountRecord;
import com.shop.mapper.PlatformAccountMapper;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * gaodo的爸爸(PlatformAccount)表服务接口
 *
 * @author makejava
 * @since 2020-11-29 09:57:06
 */
@Service
@AllArgsConstructor
public class PlatformAccountService {
    private final PlatformAccountMapper platformAccountMapper;

    public Rsp getBalance(Integer userId) {
        return Rsp.success(platformAccountMapper.getBalance(userId));
    }

    public Rsp getWithdrawRecord(Integer userId, PageParam<PlatformAccountRecord> pageParam) {
        pageParam.getModel().setUserId(userId);
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        List<PlatformAccountRecord> list = platformAccountMapper.getWithdrawRecord(pageParam.getModel());
        return Rsp.success(new PageInfo<>(list));
    }

    @Transactional
    public Rsp addWithdraw(Integer userId, PlatformAccountRecord record) {
        record.setUserId(userId);
        platformAccountMapper.addRecord(record);
        platformAccountMapper.updateBalance(userId, record.getWithdrawMoney());
        return Rsp.success(null);
    }

    public Rsp checkWithdraw(PlatformAccountRecord record) {
        platformAccountMapper.checkWithdraw(record);
        return Rsp.success(null);
    }

    public Rsp getWithdrawRecordPlatform(PageParam<PlatformAccountRecord> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
        List<PlatformAccountRecord> list = platformAccountMapper.getAllWithdrawRecord(pageParam.getModel().getStatus());
        return Rsp.success(new PageInfo<>(list));
    }
}
